package com.wiscamp.ninechapters.problems.infrastructure.po.tasks;

import com.wiscamp.ninechapters.ddd.PersistenceObject;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;

/**
 * 习题集分发记录
 *
 * @author yifeng
 * @date 2015-05-05
 */
@Data
@Entity
@Table(name = "assignments")
public class AssignmentPO implements PersistenceObject {
    @Serial
    private static final long serialVersionUID = -5999446077191747625L;

    /**
     * 编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "assignment_id", insertable = false, nullable = false)
    private long assignmentId = 0;

    /**
     * 习题集编号
     */
    @Column(name = "set_id")
    private long setId = 0;

    /**
     * 分发类型
     */
    @Column(name = "assignment_type_id", nullable = false)
    private int assignmentTypeId = 0;

    /**
     * 分发用户
     */
    @Column(name = "assign_user_id", nullable = false)
    private long assignUserId = 0;

    /**
     * 分发时间
     */
    @Column(name = "assignment_time", nullable = false)
    private LocalDateTime assignmentTime;

    /**
     * 习题集分发记录明细
     */
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "assignment_id", nullable = false, insertable = false, updatable = false)
    private Collection<AssignmentDetailPO> details = new ArrayList<>();
}